package com.zw.system.controller;/*
 *@program:java-cloud-prevalence
 *@author:
 *@Time: 2022/12/4  15:42
 *@description: SysRoleController控制类
 */

import com.zw.commons.log.annotation.Log;
import com.zw.commons.log.enums.BusinessType;
import com.zw.object.result.Result;
import com.zw.object.system.SysRole;
import com.zw.object.vo.SysRoleQueryVo;
import com.zw.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色管理接口")
@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 查询所有记录，接口
     * @return Result
     */
    @Log(title = "角色管理",businessType = BusinessType.SELECT)
    @ApiOperation("查询所有记录")
    @GetMapping("/findAll")
    public Result<List<SysRole>> findAll(){
        return sysRoleService.findAll();
    }

    /**
     * 逻辑删除接口
     * @param id Role id
     * @return Result
     */
    @Log(title = "角色管理",businessType = BusinessType.DELETE)
    @PreAuthorize("hasAuthority('bnt.sysRole.remove')")
    @ApiOperation("逻辑删除接口")
    @DeleteMapping("/remove/{id}")
    public Result removeRole(@PathVariable("id") Long id){
        return sysRoleService.remove(id);
    }

    /**
     * 条件分页查询接口
     * @param page 当前页
     * @param limit 每页记录数
     * @param sysRoleQueryVo SysRole Vo
     * @return result
     */
    @Log(title = "角色管理",businessType = BusinessType.SELECT)
    @PreAuthorize("hasAuthority('bnt.sysRole.list')")
    @ApiOperation("条件分页查询")
    @GetMapping("/{page}/{limit}")
    public Result findPageByRole(@PathVariable Long page,
                                 @PathVariable Long limit,
                                 SysRoleQueryVo sysRoleQueryVo){
        return sysRoleService.findPageByRole(page,limit,sysRoleQueryVo);
    }

    /**
     * 添加角色接口
     * @param sysRole 参数实体类
     * @return Result
     */
    @Log(title = "角色管理",businessType = BusinessType.INSERT)
    @PreAuthorize("hasAuthority('bnt.sysRole.add')")
    @ApiOperation("添加角色")
    @PostMapping("/save")
    public Result save(@RequestBody SysRole sysRole){
        return sysRoleService.saveSysRole(sysRole);
    }


    /**
     * 根据Id查询SysRole
     * @param id id
     * @return Result<SysRole>
     */
    @Log(title = "角色管理",businessType = BusinessType.SELECT)
    @ApiOperation("根据id查询")
    @PostMapping("findRoleById/{id}")
    public Result<SysRole> findRoleById(@PathVariable("id") String id){
        return sysRoleService.findSysRoleById(id);
    }


    /**
     * 修改接口
     * @param sysRole 参数实体对象
     * @return Result
     */
    @Log(title = "角色管理",businessType = BusinessType.UPDATE)
    @PreAuthorize("hasAuthority('bnt.sysRole.update')")
    @ApiOperation("最终修改")
    @PostMapping("/update")
    public Result updateRole(@RequestBody SysRole sysRole){
        return sysRoleService.updateRoleById(sysRole);
    }

    /**
     * 根据id批量删除接口
     * @param ids id集合
     * @return Result
     */
    @Log(title = "角色管理",businessType = BusinessType.DELETE)
    @PreAuthorize("hasAuthority('bnt.sysRole.batchRemove')")
    @ApiOperation("批量删除")
    @PostMapping("/batchRemove")
    public Result BatchRemove(@RequestBody List<Long> ids){
        return sysRoleService.batchRemove(ids);
    }

}
